﻿#region File Header
/***********************************************************************
 * This code is released into the public domain under WTFPL. Simply put:
 * You may use this code in whatever way you want, commercial or
 * personal.
 * 
 * Check exceltocsv.codeplex.com for updates to the original code.
************************************************************************
Author: Donald Beals
Date: September 3rd, 2013
Description: Stores symbols that help with storage management.
****************************** Change Log ******************************
09.03.13 - Created initial file. (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
#endregion

namespace ExcelToCSV
{
	/// <summary>
	/// 
	/// </summary>
	public static class IOHelper
	{
		public static void BackupFile(string filePath)
		{
			if(System.IO.File.Exists(filePath + ".old"))
				System.IO.File.Delete(filePath + ".old");
			System.IO.File.Copy(filePath, filePath + ".old");
		}

		public static string[] GetExcelFilePaths()
		{
			var output = new List<string>();
			var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			foreach(var file in Directory.EnumerateFiles(currentDirectory, "*.xlsx"))
			{
				// Skip any of the hidden, backup copies that Excel creates.
				if(Path.GetFileName(file).StartsWith("~"))
					continue;
				output.Add(file);
			}
			return output.ToArray();
		}
	}
}
